<?php
/**
 * Name: CampaignStepOneForm
 * Description: form handle campaign wizard step one
 * Author: Phu
 */
class CampaignStepTwoForm extends CFormModel {
	public $groups = array();
	public $contacts = array();
	public $emails = array();

	/**
	 * Declares the validation rules.
	 * The rules state that username and password are required,
	 * and password needs to be authenticated.
	 */
	public function rules(){
		$rules = array();
		return $rules;
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
		);
	}

	public function getGroups(){
		$results = array();
		$groups = Group::model()->findAllByAttributes(array('created_by' => Yii::app()->user->getId()));
		foreach($groups as $g){
			$results[$g->id] = $g->name." (".count($g->groupContacts).")";
		}
		return $results;
	}

	public function sync($campaign){
		foreach($this->groups as $g){
			$group = Group::model()->findByPk($g);
			if(!is_object($group)) continue;
			$campaign->addGroups($group, $campaign->id);
		}
		return true;
	}

}
?>


